﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using NSubstitute;
using DTM.Model;
using FluentAssertions;

namespace DTM.Domain.Players.Tests
{
	[TestClass()]
	public class PlayerValidatorTests
	{
		private PlayerValidator _validator;

		[TestInitialize]
		public void Initialize() {
			_validator = new PlayerValidator();
		}

		[TestMethod()]
		public void Validate_PlayerNameIsNull_ResultIsNotValid()
		{
			var player = Substitute.For<IPlayer>();
			player.Surname.Returns("Surname");
			player.Email.Returns("name.surname@hots.com");

			var result = _validator.Validate(player);

			result.IsValid.Should().BeFalse();
		}

		[TestMethod()]
		public void Validate_PlayerNameLengthGraterTham50Chars_ResultIsNotValid()
		{
			var player = Substitute.For<IPlayer>();
			player.Name.Returns("012345678901234567890123456789012345678901234567890");
			player.Surname.Returns("Surname");
			player.Email.Returns("name.surname@hots.com");

			var result = _validator.Validate(player);

			result.IsValid.Should().BeFalse();
		}

		[TestMethod()]
		public void Validate_PlayerSurnameIsNull_ResultIsNotValid()
		{
			var player = Substitute.For<IPlayer>();
			player.Name.Returns("Name");
			player.Email.Returns("name.surname@hots.com");

			var result = _validator.Validate(player);

			result.IsValid.Should().BeFalse();
		}

		[TestMethod()]
		public void Validate_PlayerSurnameLengthGraterTham50Chars_ResultIsNotValid()
		{
			var player = Substitute.For<IPlayer>();
			player.Surname.Returns("012345678901234567890123456789012345678901234567890");
			player.Name.Returns("Name");
			player.Email.Returns("name.surname@hots.com");

			var result = _validator.Validate(player);

			result.IsValid.Should().BeFalse();
		}

		[TestMethod()]
		public void Validate_PlayerEmailIsNull_ResultIsNotValid()
		{
			var player = Substitute.For<IPlayer>();
			player.Surname.Returns("Surame");
			player.Name.Returns("Name");
			
			var result = _validator.Validate(player);

			result.IsValid.Should().BeFalse();
		}

		[TestMethod()]
		public void Validate_PlayerEmailLengthGraterTham100Chars_ResultIsNotValid()
		{
			var player = Substitute.For<IPlayer>();
			player.Email.Returns("01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890");
			player.Name.Returns("Name");
			player.Surname.Returns("Surame");

			var result = _validator.Validate(player);

			result.IsValid.Should().BeFalse();
		}

		[TestMethod()]
		public void Validate_PlayerEmailFormatNotValid_ResultIsNotValid()
		{
			var player = Substitute.For<IPlayer>();
			player.Email.Returns("QWERTYUIOP");
			player.Name.Returns("Name");
			player.Surname.Returns("Surame");

			var result = _validator.Validate(player);

			result.IsValid.Should().BeFalse();
		}

		[TestMethod()]
		public void Validate_ValidPlayer_ResultIsValid()
		{
			var player = Substitute.For<IPlayer>();
			player.Email.Returns("name.surname@host.com");
			player.Name.Returns("Name");
			player.Surname.Returns("Surame");

			var result = _validator.Validate(player);

			result.IsValid.Should().BeTrue();
		}
	}
}